package com.plian.system.service.hr.recruitment.impl;

import com.plian.system.dao.sys.orgzation.OrgzationDao;
import com.plian.system.dto.hr.recruitment.PartTimeManagementDTO;
import com.plian.system.entity.hr.recruitment.PartTimeManagement;
import com.plian.system.enumeratea.PartTimeStatus;
import com.plian.system.mapper.hr.recruitment.PartTimeInfoMapper;
import com.plian.system.mapper.hr.recruitment.PartTimeManagementMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.bt.baseinfo.BaseInfoService;
import com.plian.system.service.hr.recruitment.IPartTimeInfoService;
import com.plian.system.service.hr.recruitment.IPartTimeManagementService;
import com.plian.system.service.hr.staff.IStaffFilesService;
import com.plian.system.service.sys.code.IFormCodeService;
import com.plian.system.service.sys.file.FileService;
import com.plian.system.service.sys.orgzation.OrgzationService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.hr.recruitment.PartTimeDetailVO;
import com.plian.system.vo.report.HeaderVO;
import com.plian.system.vo.report.ReportReturnVO;
import com.plian.system.vo.report.ReportVO;
import com.plian.system.wrapper.hr.recruitment.PartTimeManagementWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 *  服务实现类
 *
 * @author BladeX
 * @since 2019-12-02
 */
@Slf4j
@Service
@AllArgsConstructor
public class PartTimeManagementServiceImpl extends BaseServiceImpl<PartTimeManagementMapper, PartTimeManagement> implements IPartTimeManagementService {


	private IStaffFilesService staffFilesService;

	private FormWorkflowService formWorkflowService;

	private OrgzationService orgzationService;

	private BaseInfoService baseInfoService;

	private OrgzationDao orgzationDao;

	private IPartTimeInfoService partTimeInfoService;

	private PartTimeInfoMapper partTimeInfoMapper;

	private IFormCodeService formCodeService;

	private FileService fileService;

	private PartTimeManagementWrapper partTimeManagementWrapper;

	//名称转cod 用参照字典（参照key,<name,id>）(需确保每个名字唯一)
	private static final HashMap<String, Map<String, String>> nameMap= new HashMap<>();

//	@Override TODO DEL
//    public boolean saveOrUpdate(PartTimeManagement partTimeManagement) {
//
//		boolean flag = false;
//        if (partTimeManagement.getId()==null){
//        	partTimeManagement.setVersion("1");
//        	if(partTimeManagement.getStatus() == null){
//        		partTimeManagement.setStatus(FormStatusConstant.UNREVIEWED);
//        	}
//			partTimeManagement.setCode(formCodeService.getCode(FormTypeConstant.HR_PART_TIME_FORM));
//			partTimeManagement.setFormType(String.valueOf(FormTypeConstant.HR_PART_TIME_FORM));
//			flag = true;
//        }
//        boolean result = super.saveOrUpdate(partTimeManagement);
//		if (flag){
//			fileService.saveAll(String.valueOf(partTimeManagement.getId()), partTimeManagement.getDocList());
//		}else {
//			fileService.edit(String.valueOf(partTimeManagement.getId()), partTimeManagement.getDocList());
//		}
//
//        return result;
//    }
//
//	public boolean importSave(PartTimeManagement partTimeManagement) {
//		partTimeManagement.setVersion("1");
//		partTimeManagement.setCode(null);
//		partTimeManagement.setPartTimeJobSituation(partTimeInfoService.getPartTimeJobSituation(staffFilesService.getByStaffId(partTimeManagement.getStaffNameId())));
//		return super.saveOrUpdate(partTimeManagement);
//	}
//
//    @Override
//    public boolean deleteLogic(List<Long> ids) {
//		for (Long id : ids) {
//			PartTimeManagement partTimeManagement = getById(id);
//			if (partTimeManagement == null) {
//				return false;
//			} else if (partTimeManagement.getStatus() != null &&
//					(partTimeManagement.getStatus() != FormStatusConstant.STASH && partTimeManagement.getStatus() != FormStatusConstant.UNREVIEWED)) {
//				return false;
//			}
//			formWorkflowService.deleteProcessInstance(String.valueOf(id));
//		}
//
//		boolean result = super.deleteLogic(ids);
//		if (result){
//			partTimeInfoService.deleteLogicPartTimeManagementId(ids);
//		}
//		return result;
//    }
//
//    @Override
//    public HashMap<String,Object> commit(String id) {
//		handleStatus(Long.valueOf(id), FormStatusConstant.FLOW);
//		//将需要提交的流程变量返回，用于工作流侧
//		return new HashMap<String,Object>();
//    }
//
//    @Override
//    public Boolean finish(String id) {
//		return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH);
//    }
//
//    @Override
//    public Boolean reject(String id, int formState) {
//		return handleStatus(Long.valueOf(id), formState);
//    }
//
//    @Override
//    public Boolean cancel(Long id) {
//		return handleStatus(Long.valueOf(id), FormStatusConstant.UNREVIEWED);
//    }
//
//    /**
//     * 统一处理状态机事件方法
//     * @param id 主键
//     * @param updateStatus 更新状态
//     * @return boolean
//     */
//    private Boolean handleStatus(Long id, int updateStatus) {
//        try {
//            PartTimeManagement partTimeManagement = getById(id);
//			/**
//			 * 设置审批人和审批时间
//			 */
//			if (updateStatus == FormStatusConstant.FINISH){
//				partTimeManagement.setApprovedUser(TokenUtil.getTokenUserId());
//				Date now = DateUtil.now();
//				partTimeManagement.setApprovedTime(now);
//				partTimeInfoService.changeStatus(id, PartTimeStatus.INCUMBENCY.getStatus());
//
//				if (StringUtil.isBlank(partTimeManagement.getFilingCode())){
//					partTimeManagement.setFilingCode("兼企" + formCodeService.getFilingCode(FormTypeConstant.HR_PART_TIME_FORM));
//				}
//			}
//            partTimeManagement.setStatus(updateStatus);
//            updateById(partTimeManagement);
//            return true;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return false;
//        }
//    }
//
//	@Override
//	public boolean change(PartTimeManagement partTimeManagement) {
//		if (StringUtil.isEmpty(partTimeManagement.getVersion())) {
//			partTimeManagement.setVersion("1");
//		} else {
//			partTimeManagement.setVersion(String.valueOf(Integer.valueOf(partTimeManagement.getVersion())+1));
//		}
//
//		partTimeManagement.setUpdateTime(new Date());
//		UpdateWrapper<PartTimeManagement> updateWrapper = new UpdateWrapper<>();
//		return update(partTimeManagement,updateWrapper.eq("id",partTimeManagement.getId()));
//	}

	@Override
	public ReportReturnVO selectPartTimeManagementMain (PartTimeManagementDTO partTimeManagementDTO) throws Exception{
		ReportReturnVO reportReturnVO = new ReportReturnVO();
		ReportVO reportVO = new ReportVO();
		reportVO
			.addHeader(HeaderVO.builder().key("companyName").title("单位名称").build())
			.addHeader(HeaderVO.builder().key("name").title("姓名").build())
			.addHeader(HeaderVO.builder().key("technicalPosition").title("职务").build())
			.addHeader(HeaderVO.builder().key("partTimeEnterpriseName").title("兼职企业名称").build())
			.addHeader(HeaderVO.builder().key("proposedConcurrentPost").title("兼职企业职务").build())
			.addHeader(HeaderVO.builder().key("partTimeEnterpriseNature").title("兼职企业性质").build())
			.addHeader(HeaderVO.builder().key("partTimeStartTime").title("拟兼职开始时间").build())
			.addHeader(HeaderVO.builder().key("partTimeEndTime").title("拟兼职结束时间").build())
			.addHeader(HeaderVO.builder().key("partTimeStatus").title("目前是否兼职").build())
			.addHeader(HeaderVO.builder().key("processingStatus").title("组织部处理现状").build());

		List<PartTimeDetailVO> bondIssuanceDetailVOS = partTimeInfoMapper.selectPartTimeManagementDetail(partTimeManagementDTO.getCompanyIds(),
				partTimeManagementDTO.getStaffNameId(), partTimeManagementDTO.getPartTimeEnterpriseName(), partTimeManagementDTO.getProposedConcurrentPost(),
				partTimeManagementDTO.getDeadline1(), partTimeManagementDTO.getDeadline2());

		String companyNameSearchId = "";
		int count = 0;
		int sum = 0;
		List<PartTimeDetailVO> list2 = new ArrayList<>() ;
		for(int i =0;i< bondIssuanceDetailVOS.size();i++){
			PartTimeDetailVO pVO = bondIssuanceDetailVOS.get(i);
			if (PartTimeStatus.INCUMBENCY.getStatus() == pVO.getStatus()
					|| PartTimeStatus.REMOVAL_AUDIT.getStatus() == pVO.getStatus()){
				pVO.setPartTimeStatus("是");
			}else {
				pVO.setPartTimeStatus("否");
			}
			if(!companyNameSearchId.equals(pVO.getCompanyName())){
				if(i>0){
					PartTimeDetailVO total = new PartTimeDetailVO();
					total.setCompanyName("小计：" + count);
					list2.add(total);
					sum+=count;
				}
				companyNameSearchId = pVO.getCompanyName();
				count = 1;
			}else{
				count++;
			}
			list2.add(pVO);
		}

		sum+=count;
		PartTimeDetailVO LastTotal = new PartTimeDetailVO();
		LastTotal.setCompanyName("小计：" + count);
		list2.add(LastTotal);

		PartTimeDetailVO SumTotal = new PartTimeDetailVO();
		SumTotal.setCompanyName("总计：" + sum);
		list2.add(SumTotal);
		reportVO.setData(list2);
		reportReturnVO.setGrids(reportVO);

		return reportReturnVO;

	}

//	@Override
//	public File buildpdf(Long id,Integer type) {
//		File file = null ;
//		try {
//			PartTimeManagement partTimeManagement = getById(id);
//			if (partTimeManagement != null && ! "".equals(partTimeManagement)) {
//				PartTimeManagementVO partTimeManagementVO = partTimeManagementWrapper.entityToVO(partTimeManagement);
//				setChild(partTimeManagementVO);
////				partTimeManagementVO.setBirthday(new SimpleDateFormat("yyyy-MM-dd").format(partTimeManagementVO.getBirthday()));
//
//
//				Map< String,Object > data = new HashMap< String,Object >();
//				data.putAll(OutPdf.beanToMap(partTimeManagementVO));
//				String birthday = (String)data.get("birthday").toString().substring(0,10);
//				data.put("birthday",birthday);
//				ResourceLoader resourceLoader = new DefaultResourceLoader();
//
////				InputStream inputStream = resourceLoader.getResource("4DB6230D1BF52D9A012171F8493CF278.png").getInputStream();
////				//通过将文件转换为临时文件进行操作
////				File image = File.createTempFile("logo", ".png");
////				try {
////					FileUtils.copyInputStreamToFile(inputStream, image);
////				} finally {
////					//关闭IO
////					IOUtils.closeQuietly(inputStream);
////				}
////
////
////				if(!image.exists()){
////					data.put("image", "");
////				}
////				else{
////					/*data.put("image", image.getAbsolutePath());*/
////				}
//				File model = File.createTempFile("logo", ".pdf");
//				try {
//					if (type == 1){
//						FileUtils.copyInputStreamToFile(resourceLoader.getResource("/pdf/personnel_part_time_management.pdf").getInputStream(), model);
//					}else {
//						FileUtils.copyInputStreamToFile(resourceLoader.getResource("/pdf/personnel_part_time_management2.pdf").getInputStream(), model);
//					}
//
//				} finally {
//					//关闭IO
//					//IOUtils.closeQuietly(inputStream);
//				}
//				String fileName = model.getPath();
//				PdfReader reader = new PdfReader(fileName);
//				ByteArrayOutputStream bos = new ByteArrayOutputStream();
//				/* 将要生成的目标PDF文件名称 */
//				PdfStamper ps = new PdfStamper(reader, bos);
//				/* 使用中文字体 */
//				BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//				ArrayList < BaseFont > fontList = new ArrayList < BaseFont > ();
//				fontList.add(bf);
//
//				/* 取出报表模板中的所有字段 */
//				AcroFields fields = ps.getAcroFields();
//				fields.setSubstitutionFonts(fontList);
//				for (String key: data.keySet()) {
//					String value = data.get(key).toString();
//					if(data.get(key) instanceof Date){
//						value=processDate((Date)data.get(key));
//					}
//					fields.setField(key, value); // 为字段赋值,注意字段名称是区分大小写的
//				}
//				//已兼职情况
//				fields.setField("parttimeJobSituation", partTimeManagement.getPartTimeJobSituation());
//				//拟兼职时间
//				List<PartTimeInfo> partTimeInfos = partTimeManagementVO.getPartJobSituation();
//				if (CollectionUtil.isNotEmpty(partTimeInfos)){
//					String partTimeJobTimeStr = "";
//					String proposedConcurrentPost = "";
//					String parttimeJobReason = "";
//					for (PartTimeInfo partTimeInfo : partTimeInfos){
//						if(Optional.ofNullable(partTimeInfo.getPartTimeStartTime()).isPresent() && Optional.ofNullable(partTimeInfo.getPartTimeEndTime()).isPresent()) {
//							String startStr = DateUtil.formatDate(partTimeInfo.getPartTimeStartTime());
//							String endStr = DateUtil.formatDate(partTimeInfo.getPartTimeEndTime());
//							if (StringUtil.isBlank(partTimeJobTimeStr)) {
//									partTimeJobTimeStr +=  startStr+ "-" + endStr;
//							} else {
//								partTimeJobTimeStr += "，" + startStr+ "-" + endStr;
//							}
//						}
//
//						if(Optional.ofNullable(partTimeInfo.getPartTimeEnterpriseName()).isPresent() && Optional.ofNullable(partTimeInfo.getProposedConcurrentPost()).isPresent()) {
//							if (StringUtil.isBlank(proposedConcurrentPost)) {
//								proposedConcurrentPost += partTimeInfo.getPartTimeEnterpriseName() + partTimeInfo.getProposedConcurrentPost();
//							} else {
//								proposedConcurrentPost += "，" + partTimeInfo.getPartTimeEnterpriseName() + partTimeInfo.getProposedConcurrentPost();
//							}
//						}
//
//						if(Optional.ofNullable(partTimeInfo.getPartTimeJobReason()).isPresent()) {
//							if (StringUtil.isBlank(parttimeJobReason)) {
//								parttimeJobReason += partTimeInfo.getPartTimeJobReason();
//							} else {
//								parttimeJobReason += "，" + partTimeInfo.getPartTimeJobReason();
//							}
//						}
//
//					}
//					fields.setField("proposedConcurrentPost", proposedConcurrentPost);
//					fields.setField("parttimeJobTime", partTimeJobTimeStr);
//					fields.setField("parttimeJobReason", parttimeJobReason);
//				}
//
//
////				if(!StringUtil.isEmpty(data.get("image"))){
////					//待加入图片的文字域,设置为隐藏;不然会遮挡掉图片的
////					OutPdf.insertImage(fields, ps, "image", (String)data.get("image"));
////				}
//				/* 必须要调用这个，否则文档不会生成的 */
//				ps.setFormFlattening(true);
//				ps.close();
//				File dir = new File(model.getParent());
//				file = File.createTempFile("part_time_management", ".pdf", dir);
//				OutputStream fos = new FileOutputStream(file);
//				fos.write(bos.toByteArray());
//				fos.flush();
//				fos.close();
//				bos.close();
//			}
//
//		} catch(Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return file;
//	}
//
//
//
//	private static String processDate(Date date){
//		SimpleDateFormat formatter=new SimpleDateFormat("yyyy/MM/dd");
//		return date==null?"":formatter.format(date);
//	}
//
//
//	private void initMap() {
//		//注：以下key值与实际配置的参照无关联，仅为了方便理解使用了相同名称
//		//民族
//		nameMap.put("nationRef", baseInfoService.getChildNameMap(ValueSetConstant.NATION));
//		//性别
//		nameMap.put("genderRef", baseInfoService.getChildNameMap(ValueSetConstant.GENDER));
//		//职务名称
////		nameMap.put("jobNameRef", baseInfoService.getChildNameMap(ValueSetConstant.JOB_NAME));
//
//		try{
//			List<PageData> allOrgs =  orgzationDao.list(null);
//
//			if (CollectionUtil.isNotEmpty(allOrgs)){
//				HashMap<String, String> orgMap = new HashMap<>();
//				for (PageData pageData : allOrgs){
//					orgMap.put((String)pageData.get("name"), (String)pageData.get("id"));
//				}
//
//				nameMap.put("unitRef",orgMap);
//			}
//
//		}catch (Exception e){
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		List<StaffFiles> staffFilesList = staffFilesService.list();
//		Map<String, String> map = new HashMap<>();
//		if (CollectionUtil.isNotEmpty(staffFilesList)){
//			for (StaffFiles staffFiles : staffFilesList){
//				map.put(EncryptUtil.decryptBase64(staffFiles.getStaffCode(), BASE64_KEY), String.valueOf(staffFiles.getId()));
//			}
//		}
//		nameMap.put("staffFilesRef", map);
//	}
//	/**
//	 * 导入 有问题 得改
//	 *
//	 * @param multipartFile excel
//	 * @return object
//	 */
//	@Override
//	public ImportResult importExcel(MultipartFile multipartFile) {
//		try {
//			InputStream inputStream = multipartFile.getInputStream();
//            List<Object> partTimeManagementReadExcels = new ArrayList<>();
//            EasyExcel.read(inputStream).build()
//                    .read(EasyExcel.readSheet(1).headRowNumber(1).head(PartTimeManagementExcelBean.class)
//                            .registerReadListener(new PageReadListener<>(list -> partTimeManagementReadExcels.addAll(list))).build());
//			ImportResult importResult = checkData(partTimeManagementReadExcels, list());
//			if (!importResult.isSuccess()) {
//				return importResult;
//			}
//			for (Object readExcel : partTimeManagementReadExcels) {
//				PartTimeManagementExcelBean partTimeManagementExcelBean = (PartTimeManagementExcelBean) readExcel;
//				//单位名称
//				if (partTimeManagementExcelBean.getCompanyId() != null){
//					partTimeManagementExcelBean.setCompanyId(nameMap.get("unitRef").get(partTimeManagementExcelBean.getCompanyId()));
//				}
//				//身份证编码
//				if (partTimeManagementExcelBean.getStaffNameId() != null){
//					partTimeManagementExcelBean.setStaffNameId(nameMap.get("staffFilesRef").get(partTimeManagementExcelBean.getStaffNameId()));
//				}
//
//				//性别
//				if (partTimeManagementExcelBean.getGenderId() != null){
//					partTimeManagementExcelBean.setGenderId(nameMap.get("genderRef").get(partTimeManagementExcelBean.getGenderId()));
//				}
//				//民族
//				if (partTimeManagementExcelBean.getNationId() != null){
//					partTimeManagementExcelBean.setNationId(nameMap.get("nationRef").get(partTimeManagementExcelBean.getNationId()));
//				}
//				//职务
////				if (partTimeManagementExcelBean.getPresentPostId() != null){
////					partTimeManagementExcelBean.setPresentPostId(nameMap.get("jobNameRef").get(partTimeManagementExcelBean.getPresentPostId()));
////				}
//				PartTimeManagement partTimeManagement = (PartTimeManagement) ImportExcelUtil.getEntityByExcelBean((PartTimeManagementExcelBean) readExcel, new PartTimeManagement());
//				partTimeManagement.setStatus(FormStatusConstant.FINISH);
//				partTimeManagement.setApprovedUser(TokenUtil.getTokenUserId());
//				partTimeManagement.setApprovedTime(new Date());
//				Calendar calendar = Calendar.getInstance();
////				partTimeManagement.setFilingCode("兼企"+calendar.get(Calendar.YEAR)+billcodeClient.getDocCodeByKey("兼企",calendar.get(Calendar.YEAR)+"",3));
//
//				//入库
//				try {
//					importSave(partTimeManagement);
//				} catch (Exception e) {
//					log.error(partTimeManagement + "导入失败");
//					return new ImportResult(false, partTimeManagement + "导入失败");
//				}
//			}
//
//			//return personReadExcels;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			log.error("解析失败");
//			return new ImportResult(false, "解析失败");
//		}
//		return new ImportResult(true, "导入成功");
//
//	}
//
//	private final static String OBJECT_MSG = "未找到对应对象!";
//	/**
//	 * 校验数据
//	 *
//	 * @param readExcels excel读出来的list
//	 * @param partTimeManagementList 查询出来的全量list
//	 * @return 通过true, 不通过false
//	 */
//	private ImportResult checkData(List<Object> readExcels, List<PartTimeManagement> partTimeManagementList) {
//		ImportResult importResult = new ImportResult(true, "");
//		List<Object> objectPersonList = new ArrayList<>(partTimeManagementList);
//		StringBuilder msg = new StringBuilder();
//		//List<String> codeList = new ArrayList<>();
//
//		for (Object readExcel : readExcels) {
//			PartTimeManagementExcelBean partTimeManagementExcelBean = (PartTimeManagementExcelBean) readExcel;
//			//codeList.add(partTimeManagementExcelBean.getCode());
//
//			int index = readExcels.indexOf(readExcel);
//			//必填校验
//			msg.append(ImportExcelUtil.checkEmpty("2", "单位名称", partTimeManagementExcelBean.getCompanyId(), index).getMsg());
//			msg.append(ImportExcelUtil.checkEmpty("2", "姓名", partTimeManagementExcelBean.getStaffNameId(), index).getMsg());
//			msg.append(ImportExcelUtil.checkEmpty("2", "性别", partTimeManagementExcelBean.getGenderId(), index).getMsg());
//			msg.append(ImportExcelUtil.checkEmpty("2", "兼职企业名称", partTimeManagementExcelBean.getParttimeEnterpriseName(), index).getMsg());
//			msg.append(ImportExcelUtil.checkEmpty("2", "兼职企业性质", partTimeManagementExcelBean.getParttimeEnterpriseNature(), index).getMsg());
//			msg.append(ImportExcelUtil.checkEmpty("2", "拟兼任职务（社会团体）", partTimeManagementExcelBean.getProposedConcurrentPost(), index).getMsg());
//
//			//先判断类型
//
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, "2", "出生年月",
//				partTimeManagementExcelBean.getBirthday(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, "2", "入党时间",
//				partTimeManagementExcelBean.getJoinPartyTime(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, "2", "参加工作时间",
//				partTimeManagementExcelBean.getWorkTime(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, "2", "拟兼职开始时间",
//				partTimeManagementExcelBean.getParttimeJobTime(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, "2", "拟兼职结束时间",
//				partTimeManagementExcelBean.getDef15(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, "2", "性别",
//				partTimeManagementExcelBean.getGenderId(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, "2", "民族",
//				partTimeManagementExcelBean.getNationId(), index).getMsg());
//			msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, "2", "现任职务",
//				partTimeManagementExcelBean.getPresentPostId(), index).getMsg());
//
//		}
//		//判断完类型若有错直接返回
//		if (msg.toString().length() > 0) {
//			return new ImportResult(false, msg.toString());
//		}
//
//		//对象和字典是否存在校验
//		for (Object readExcel : readExcels) {
//			PartTimeManagementExcelBean partTimeManagementExcelBean = (PartTimeManagementExcelBean) readExcel;
//			int index = readExcels.indexOf(readExcel);
//
//			//现任职务（对象）
////			if(!nameMap.get("jobNameRef").containsKey(partTimeManagementExcelBean.getPresentPostId())){
////				msg.append(ImportExcelUtil.msgBuilder("2",String.valueOf(index + 2),"现任职务", partTimeManagementExcelBean.getPresentPostId(), OBJECT_MSG));
////			}
//
//			//身份证（对象）
//			if(!nameMap.get("staffFilesRef").containsKey(partTimeManagementExcelBean.getStaffNameId())){
//				msg.append(ImportExcelUtil.msgBuilder("2",String.valueOf(index + 2),"身份证", partTimeManagementExcelBean.getStaffNameId(), OBJECT_MSG));
//			}
//
//			//单位名称（对象）
//			if(!nameMap.get("unitRef").containsKey(partTimeManagementExcelBean.getCompanyId())){
//				msg.append(ImportExcelUtil.msgBuilder("2",String.valueOf(index + 2),"单位名称", partTimeManagementExcelBean.getCompanyId(), OBJECT_MSG));
//			}
//
//			//身份证（对象）
//			if(!nameMap.get("genderRef").containsKey(partTimeManagementExcelBean.getGenderId())){
//				msg.append(ImportExcelUtil.msgBuilder("2",String.valueOf(index + 2),"性别", partTimeManagementExcelBean.getGenderId(), OBJECT_MSG));
//			}
//
//			//身份证（对象）
//			if(!nameMap.get("nationRef").containsKey(partTimeManagementExcelBean.getNationId())){
//				msg.append(ImportExcelUtil.msgBuilder("2",String.valueOf(index + 2),"民族", partTimeManagementExcelBean.getNationId(), OBJECT_MSG));
//			}
//
//			//员工和单位是否匹配校验
//			msg.append(checkCompany("2", "单位名称", index, partTimeManagementExcelBean.getCompanyId(), partTimeManagementExcelBean.getStaffNameId()));
//
//		}
//
//		//统一放置报错
//		if (msg.toString().length() > 0) {
//			importResult = new ImportResult(false, msg.toString());
//		}
//		return importResult;
//	}
//
//	private String checkCompany(String sheetNo, String columnName, Integer index, String companyName, String staffName) {
//		String result = "";
//		Boolean exist = false;
//
//		if (Optional.ofNullable(companyName).isPresent()) {
//
//			StaffFiles staffFiles = new StaffFiles();
//			staffFiles.setStaffName(staffName);
//			List<StaffFiles> staffFilesList = staffFilesService.list(Condition.getQueryWrapper(staffFiles));
//
//			for (StaffFiles staff : staffFilesList){
//				PageData org = orgzationService.getCompanyNameById(staff.getCompanyNameId());
//				if(org!=null){
//					if (org.getString("name").equals(columnName)){
//						exist = true;
//						break;
//					}
//				}
//			}
//
//			if (!exist) {
//				result = "sheet" + sheetNo + "第" + String.valueOf(index + 2) + "行(" + columnName + "=" + companyName + " 姓名="+staffName+")" + "员工和单位名称不匹配" + System.getProperty("line.separator");
//			}
//		}
//		return result;
//	}
//
////	private String checkJobName(String sheetNo, String columnName, Integer index, String companyName, Long unitId, String presentPostCode) {
////		String result = "";
////		Boolean exist = false;
////
////		if (Optional.ofNullable(companyName).isPresent()) {
////			JobName jobName = new JobName();
////			jobName = jobNameClient.getJobNameByCodeOrg(presentPostCode,unitId);
////
////			if (Optional.ofNullable(jobName).isPresent()){
////				exist = true;
////			}
////
////			if (!exist) {
////				result = "sheet" + sheetNo + "第" + String.valueOf(index + 2) + "行(" + columnName + "=" + companyName + " 职务名称编码="+presentPostCode+")" + "职务名称和单位名称不匹配" + System.getProperty("line.separator");
////			}
////		}
////		return result;
////	}
//
//	@Override
//	public PartTimeManagementVO setChild(PartTimeManagementVO partTimeManagementVO) {
//		if(!Optional.ofNullable(partTimeManagementVO).isPresent()){
//			return null;
//		}
//		QueryWrapper<PartTimeInfo> queryWrapper = new QueryWrapper<>();
//		queryWrapper.eq("part_time_management_id", partTimeManagementVO.getId());
//		List<PartTimeInfo> partTimeInfos = partTimeInfoService.list(queryWrapper);
//		partTimeManagementVO.setPartJobSituation(partTimeInfos);
//
//		return partTimeManagementVO;
//	}
//
//	@Override
//	public List<PartTimeManagement> selectExpired() {
//		return baseMapper.selectExpired();
//	}
//
//	@Override
//	public ObjResult getDetailObj(PartTimeManagementVO partTimeManagementVO) {
//		if(!Optional.ofNullable(partTimeManagementVO).isPresent()){
//			return new ObjResult(CommonCode.FAIL);
//		}
//
//		PageData pd = new PageData();
//		ObjectMapper mapper = new ObjectMapper();
//		String json = JSON.toJSONStringWithDateFormat(partTimeManagementVO, DateUtil.PATTERN_DATETIME);
//		try {
//			pd.putAll(mapper.readValue(json, new TypeReference<HashMap<String, String>>() {}));
//		}catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			return new ObjResult(CommonCode.ERROR);
//		}
//
//		pd.put("partTimeInfos",
//				partTimeInfoService.list(new QueryWrapper<PartTimeInfo>().eq("part_time_management_id", partTimeManagementVO.getId()))
//						.stream().collect(Collectors.toList())
//		);
//
//		ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
//		objResult.setPageData(pd);
//		return objResult;
//	}
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public Boolean submit(PartTimeManagement partTimeManagement) {
//		boolean result = saveOrUpdate(partTimeManagement);
//		if (result){
//			List<PartTimeInfo> partTimeInfos = partTimeManagement.getPartTimeInfos();
//			if (CollectionUtil.isNotEmpty(partTimeInfos)){
//				for (PartTimeInfo partTimeInfo : partTimeInfos){
//					if (partTimeInfo.getId() != null &&
//							Optional.ofNullable(partTimeInfo.getIsDeleted()).isPresent() && partTimeInfo.getIsDeleted().intValue() == 1) {
//						partTimeInfoService.removeById(partTimeInfo.getId());
//					}else {
//						partTimeInfo.setPartTimeManagementId(partTimeManagement.getId());
//						partTimeInfo.setStaffNameId(partTimeManagement.getStaffNameId());
//						partTimeInfo.setPartTimeManagementId(partTimeManagement.getId());
//						partTimeInfo.setStatus(PartTimeStatus.AUDIT.getStatus());
//						partTimeInfoService.saveOrUpdate(partTimeInfo);
//					}
//				}
//			}
//		}
//
//		HashMap<String, Object> processVariable = new HashMap<>();
//		formWorkflowService.startProcessAndSimulate(String.valueOf(partTimeManagement.getId()),partTimeManagement.getFormType(),processVariable);
//
//		return result;
//	}
//
//	@Override
//	public String checkSubmit(PartTimeManagement partTimeManagement) {
//		if (Optional.ofNullable(partTimeManagement).isPresent()){
//			if (CollectionUtil.isEmpty(partTimeManagement.getPartTimeInfos())){
//				return "拟兼职信息未填写";
//			}
//		}
//		return null;
//	}
//
//	@Override
//	public List<PageData> findByIds(List<String> formIds) {
//		LambdaQueryWrapper<PartTimeManagement> queryWrapper = new LambdaQueryWrapper<>();
//		queryWrapper.in(PartTimeManagement::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//		List<PartTimeManagement> recruitmentManagements = list(queryWrapper);
//		List<PartTimeManagementVO> recruitmentManagementVOS = partTimeManagementWrapper.entityToVO(recruitmentManagements);
//		List<PageData> pageDataList = new ArrayList<>();
//		try{
//			if (CollectionUtil.isNotEmpty(recruitmentManagementVOS)){
//				for (PartTimeManagementVO vo : recruitmentManagementVOS){
//					PageData pd = new PageData();
//					pd.put("id", vo.getId());
//					pd.put("UNITNAME", vo.getCompanyName());
//					pd.put("APPLICANTNAME", vo.getCreateUserName());
//					pd.put("applicantId", vo.getCreateUser());
//					pd.put("applyOrganizationId", vo.getCompanyNameId());
//					pd.put("formType", FormTypeConstant.HR_PART_TIME_FORM);
//					pd.put("orgName", vo.getCompanyName());
//					pageDataList.add(pd);
//				}
//			}
//
//			return pageDataList;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return pageDataList;
//	}
//
//	@Override
//	public void goBackToStash(String formId) {
//		partTimeInfoService.changeStatus(Long.valueOf(formId), PartTimeStatus.AUDIT.getStatus());
//		handleStatus(Long.valueOf(formId), UNREVIEWED);
//	} TODO DEL
}
